from concrete_command import *
from command import *
from facility import *
from typing import List

class RemoteControl:
    def __init__(self):
        self._on_commands: List[Command] = []
        self._off_commands: List[Command] = []

        for i in range(7):
            self._on_commands.append(NoCommand())
            self._off_commands.append(NoCommand())

    def __str__(self):
        result = ["\n----- Remote Control -----\n"]
        for i in range(len(self._on_commands)):
            result.append(f"[slot {i}] {type(self._on_commands[i])}    {type(self._off_commands[i])}\n")
        return "".join(result)

    def set_command(self, slot: int, on_command: Command, off_command: Command):
        self._on_commands[slot] = on_command
        self._off_commands[slot] = off_command

    def on_button_was_pushed(self, slot: int):
        self._on_commands[slot].execute()

    def off_button_was_pushed(self, slot: int):
        self._off_commands[slot].execute()


if __name__ == '__main__':
    controller = RemoteControl()

    living_room_light = Light("Living Room")
    kitchen_light = Light("Kitchen")
    ceiling_fan = CeilingFan("Living Room")
    garage_door = GarageDoor("Garage")
    stereo = Stereo("Living Room")

    living_room_light_on = LightOnCommand(living_room_light)
    living_room_light_off = LightOffCommand(living_room_light)
    kitchen_light_on = LightOnCommand(kitchen_light)
    kitchen_light_off = LightOffCommand(kitchen_light)

    ceiling_fan_on = CeilingFanOnCommand(ceiling_fan)
    ceiling_fan_off = CeilingFanOffCommand(ceiling_fan)

    garage_door_up = GarageDoorUpCommand(garage_door)
    garage_door_down = GarageDoorDownCommand(garage_door)

    stereo_on_with_cd = StereoOnWithCDCommand(stereo)
    stereo_off = StereoOffCommand(stereo)

    controller.set_command(0, living_room_light_on, living_room_light_off)
    controller.set_command(1, kitchen_light_on, kitchen_light_off)
    controller.set_command(2, ceiling_fan_on, ceiling_fan_off)
    controller.set_command(3, stereo_on_with_cd, stereo_off)
    controller.set_command(4, garage_door_up, garage_door_down)

    print(controller)

    controller.on_button_was_pushed(0)
    controller.off_button_was_pushed(0)
    controller.on_button_was_pushed(1)
    controller.off_button_was_pushed(1)
    controller.on_button_was_pushed(2)
    controller.off_button_was_pushed(2)
    controller.on_button_was_pushed(3)
    controller.off_button_was_pushed(3)
    controller.on_button_was_pushed(4)
    controller.off_button_was_pushed(4)